

import {createSlice,createAsyncThunk} from "@reduxjs/toolkit"
import axios from "axios"

export let getUserRoutesThunk = createAsyncThunk('getUserRoutes',async(id)=>{
    let res = await axios.get(`http://192.168.137.1:8001/getroutes/${id}`)
    localStorage.setItem("userRoutes",JSON.stringify(res.data.data))
    return res.data.data
})

let _userRoutes = localStorage.getItem("userRoutes")
let userSlice = createSlice({
    name:"userSlice",
    initialState:{
        userRoute: _userRoutes ? JSON.parse(_userRoutes) : []
    },
    reducers:{

    },
    extraReducers:{
        [getUserRoutesThunk.fulfilled]:(state,action)=>{
            console.log("userroute",action)
            state.userRoute = action.payload
        }
    }
})


export default userSlice.reducer